#ifndef AST_STATEMENT_ITERATION_STMT_H
#define AST_STATEMENT_ITERATION_STMT_H

#include "../ASTNode.h"
class Expression;
class Statement;
class Declaration;
/*
C99   6.8.5
iteration-statement:
		while   (   expression   )   statement
		do   statement   while   (   expression   );
		for   (   expression(opt)   ;   expression(opt)   ;   expression(opt)   )   statement
		for   (   declaration   expression(opt)   ;   expression(opt)   )   statement
*/
class IterationStmt : public ASTNode
{
public:
	enum {
		while_stmt,
		do_stmt,
		decl_for_stmt,
		for_stmt,
	};
protected:
	IterationStmt(void)
		: ASTNode(ASTNode::iteration_statement){};
public:
	IterationStmt(Expression *pExpr, Statement *pStmt, int iType)
		: ASTNode(ASTNode::iteration_statement)
		, m_pWhileExpr(pExpr)
		, m_pDoStmt(pStmt)
		, m_iType(iType){};

	IterationStmt(Expression *pExpr1, Expression *pExpr2, Expression *pExpr3, Statement *pStmt)
		: ASTNode(ASTNode::iteration_statement)
		, m_pForStmt(pStmt)
		, m_pExpr1(pExpr1)
		, m_pExpr2(pExpr2)
		, m_pExpr3(pExpr3)
		, m_iType(for_stmt){};

	IterationStmt(Declaration *pDecl, Expression *pExpr2, Expression *pExpr3, Statement *pStmt)
		: ASTNode(ASTNode::iteration_statement)
		, m_pForStmt(pStmt)
		, m_pDecl(pDecl)
		, m_pExpr2(pExpr2)
		, m_pExpr3(pExpr3)
		, m_iType(decl_for_stmt){};

	virtual ~IterationStmt(void);

	virtual void					codeGen();

protected:
	tiny_int						m_iType;
	union{
		struct{
			Expression *			m_pWhileExpr;
			Statement *				m_pDoStmt;
		};
		struct{
			union{
				Expression *		m_pExpr1;
				Declaration *		m_pDecl;
			};
			Expression *			m_pExpr2;
			Expression *			m_pExpr3;
			Statement *				m_pForStmt;
		};
	};
};


#endif

